#include "iostream"
#include <cstdlib>
#include <cstring>

using namespace std;


class Name
{
public:
	Name(const char *pname)
	{
		cout<<"construction method Name(const char *pname)"<<endl;
		size = strlen(pname);
		pName = (char *)malloc(size + 1);
		strcpy(pName, pname);
	}
	Name(Name &obj)
	{
		cout<<"copy construction method Name(Name &obj)"<<endl;
		//用obj来初始化自己
		pName = (char *)malloc(obj.size + 1);
		strcpy(pName, obj.pName);
		size = obj.size;
	}
	~Name()
	{
		cout<<"开始析构"<<endl;
		if (pName!=NULL)
		{
			free(pName);
			pName = NULL;
			size = 0;
		}
	}
public:
	void operator=(Name &obj3)
	{
		if (pName != NULL)
		{
			free(pName);
			pName = NULL;
			size = 0;
		}
		cout<<"operator=。。。。"<<endl;

		//用obj3来=自己
		pName = (char *)malloc(obj3.size + 1);
		strcpy(pName, obj3.pName);
		size = obj3.size;

	}

protected:
private:
	char *pName;
	int size;
};

//对象的初始化 和 对象之间=号操作是两个不同的概念
void playObj()
{
	Name obj1("obj1.....");
	Name obj2 = obj1; //obj2创建并初始化

	Name obj3("obj3...");

	//重载=号操作符
	obj2 = obj3; //=号操作

}
int main()
{
	playObj();
	return 0;
}